package awd.bj.jls.webs.api;

import java.util.List;
import java.util.Map;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import awd.bj.jls.webs.api.hystrix.DictionaryApiFallBackFactory;
import awd.bj.jls.webs.utils.PagerResult;
import awd.bj.jls.webs.utils.QueryParam;
import awd.bj.jls.webs.utils.ResponseMessage;
import awd.bj.manager.model.DictionaryModel;


@FeignClient(name = "${awd.api.dictionary:AWD-MIS-MANAGER-SERVER}", fallbackFactory = DictionaryApiFallBackFactory.class)
@Component
public interface DictionaryApi {

    @PostMapping("/dictionary/list")
    public ResponseMessage<List<DictionaryModel>> list(@RequestBody Map<String, String[]> map);

    /**
     * 根据类型获取字典
     *
     * @param filed
     * @return
     */
    @RequestMapping(value = "/dictionary/getbyfield/{field}")
    ResponseMessage<List<DictionaryModel>> getByField(
            @PathVariable(value = "field") String filed
    );

    /**
     * 获取所有字典类型名
     *
     * @return
     */
    @RequestMapping(value = "/dictionary/getallfields")
    ResponseMessage<List<Map<String, Object>>> getAllFields();

    /**
     * 根据类型分页查询字典
     *
     //* @param map
     * @return
     */
    @GetMapping(value = "/dictionary")
    ResponseMessage<PagerResult<DictionaryModel>> getPageByfields(QueryParam qParam);

    /**
     * 根据id 获取字典信息信息
     *
     * @param id
     * @return
     */
    @RequestMapping("/dictionary/{id}")
    ResponseMessage<DictionaryModel> getByid(@PathVariable("id") String id);

    /**
     * 新增字典信息
     *
     * @return
     */
    @PostMapping("/dictionary")
    public ResponseMessage<String> save(@RequestBody DictionaryModel dictionaryModel);

    /**
     * 根据id 如果没有新建有就更新字典信息
     *
     * @return
     */
    @PatchMapping("/dictionary")
    public ResponseMessage<String> saveorupdate(@RequestBody DictionaryModel dictionaryModel);

    /**
     * 根据id 更新字典信息
     *
     * @param id
     * @return
     */
    @PutMapping("/dictionary/{id}")
    public ResponseMessage<String> update(@RequestParam(value = "id") String id, @RequestBody DictionaryModel dictionaryModel);

    /**
     * 字典信息查询（带分页）
     *
     * @return
     */
    @PostMapping("/dictionary/query")
    ResponseMessage<PagerResult<DictionaryModel>> query(@RequestBody Map<String, String[]> params);


}
